package com.xiaoming.e3mall.controller;

import com.xiaoming.e3mall.common.pojo.EasyUITreeNode;
import com.xiaoming.e3mall.common.utils.E3Result;
import com.xiaoming.e3mall.content.service.ContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 前台首页的内容管理
 */

@RequestMapping("/content/category")
@Controller
public class ContentCategoryContorller {

    @Autowired
    private ContentCategoryService contentCategoryService;

    /**
     * 加载首页的区域分类
     */
    @RequestMapping("/list")
        @ResponseBody
    public List<EasyUITreeNode> getContentCategoryList(
            @RequestParam(name = "id",defaultValue = "0") Long parentId){
        return contentCategoryService.getContentCategoryList(parentId);
    }

    /**
     * 添加首页的分类
     */
    @RequestMapping("/create")
        @ResponseBody
    public E3Result addContentCategory(Long parentId,String name){
        return contentCategoryService.addContentCategory(parentId,name);
    }


    /**
     * 更新首页分类名称
     */

    @RequestMapping("/update")
        @ResponseBody
    public E3Result updateContentCategory(long id,String name){
        return contentCategoryService.updateContentCategory(id,name);
    }


    /**
     * 删除首页分类节点
     */
    @RequestMapping("/delete")
        @ResponseBody
    public E3Result deleteContentCategory(Long id){
        return contentCategoryService.deleteContentCategory(id);
    }

}
